// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/**
 * @brief
 *
 * @version  0.1
 * @author   yuanchenxi
 * @date     2024.12.20
 */
#include "Import/BDFImport/BulkData/Property/PFASTParser.h"

#include "gtest/gtest.h"

#include "DataStructure/Common/Constant.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Property/IPFASTService.h"

#include "Import/BDFImport/BDFParserBase.h"

using SG::DataStructure::Common::TOLERANCE;
using namespace SG::DataStructure::FEM;
using namespace SG::DBManager;
using namespace SG::Import;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class PFASTParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (PFASTParserTest, ParseEntry1)
{  //                                   $1234567$1234567$1234567$1234567$1234567$1234567$1234567$1234567$1234567$1234567
    std::vector<std::string> Entry = { "PFAST        543     6.4       0       0 658192.  21971.  21971.     1.0+       ",
                                       "+            2.0     3.0     4.0       5                                FASTENER" };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParsePFAST (DB_SERVICEFACTORY, dividedEntryInfo);
    SG::DataStructure::FEM::PFASTData data;

    ASSERT_TRUE (DB_SERVICEFACTORY->get<IPFASTService> ()->FindById (543, data) == SG::DataStructure::Common::Status::STATUS_Success);

    ASSERT_TRUE (data.m_id == 543);
    ASSERT_TRUE (data.m_MID == 0);
    ASSERT_NEAR (data.m_D, 6.4, TOLERANCE);
    ASSERT_EQ (data.m_MCID, 0);
    ASSERT_EQ (data.m_MFLAG, 0);
    ASSERT_NEAR (data.m_KT[0], 658192, TOLERANCE);
    ASSERT_NEAR (data.m_KT[1], 21971, TOLERANCE);
    ASSERT_NEAR (data.m_KT[2], 21971, TOLERANCE);
    ASSERT_NEAR (data.m_KR[0], 1, TOLERANCE);
    ASSERT_NEAR (data.m_KR[1], 2, TOLERANCE);
    ASSERT_NEAR (data.m_KR[2], 3, TOLERANCE);
    ASSERT_NEAR (data.m_CMASS, 4, TOLERANCE);
    ASSERT_NEAR (data.m_GE, 5, TOLERANCE);
    ASSERT_TRUE (data.m_WELDTYPE == -1);
    ASSERT_NEAR (data.m_MINLEN, 0, 0.2);
    ASSERT_NEAR (data.m_MAXLEN, 0, 5.0);
}
